package com.example;

/*
 import java.util.ArrayList;
 import java.util.List;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 import java.util.regex.PatternSyntaxException;

 import android.content.Context;
 import android.content.Intent;
 import android.content.pm.ApplicationInfo;
 import android.content.pm.PackageManager;
 import android.database.Cursor;
 import android.database.sqlite.SQLiteDatabase;
 import android.util.Log;

 import com.example.singletones.SQLHelper;
 import com.example.singletones.contextObj;

 public class ActionHandlerMannager {
 private Context mContext = null;
 private SQLHelper mSQLHelper;
 private SQLiteDatabase db;
 private static ActionHandlerMannager instance = null;

 public static ActionHandlerMannager getInstance(Context context) {
 if (instance == null) {
 instance = new ActionHandlerMannager(context);
 }
 return instance;
 }

 protected ActionHandlerMannager(Context context) {
 if (context != null) {
 setmContext(context);

 mSQLHelper = new SQLHelper(this.mContext);
 db = mSQLHelper.getWritableDatabase();
 db.execSQL("CREATE TABLE IF NOT EXISTS Actions (id INTEGER PRIMARY KEY,Action TEXT)");
 db.execSQL("delete from Actions");
 db.execSQL("insert into Actions (id,Action) values ('1','ActionType=startApp;Parameter1=com.waze;')");
 }
 }

 public void doAction(String[] id) {

 db = mSQLHelper.getWritableDatabase();
 Cursor cursor = db.rawQuery(
 "select `Action` from `Actions` where id = ?", id);
 String Data = null;
 if (cursor.moveToFirst()) {
 Data = cursor.getString(0);

 String ResultString = null;
 try {
 Pattern regex = Pattern.compile("ActionType=([^;]+);");
 Matcher regexMatcher = regex.matcher(Data);
 if (regexMatcher.find()) {
 ResultString = regexMatcher.group(1);
 }
 } catch (PatternSyntaxException ex) {
 // Syntax error in the regular expression
 }

 List<String> matchList = new ArrayList<String>();
 try {
 Pattern regex = Pattern.compile("Parameter\\d+=([^;]+);");
 Matcher regexMatcher = regex.matcher(Data);
 while (regexMatcher.find()) {
 matchList.add(regexMatcher.group(1));
 }
 } catch (PatternSyntaxException ex) {
 // Syntax error in the regular expression
 }

 if (ResultString != null) {
 Log.d("aaa", "" + matchList.size());
 if (matchList.size() == 1) {
 StartApp(matchList.get(0));
 }
 }
 }

 }

 public void getAppsList() {
 final PackageManager pm = contextObj.getInstance().getmContext()
 .getPackageManager();
 // get a list of installed apps.
 List<ApplicationInfo> packages = pm
 .getInstalledApplications(PackageManager.GET_META_DATA);

 for (ApplicationInfo packageInfo : packages) {

 Log.d("tag", "Installed package :" + packageInfo.packageName);
 Log.d("tag",
 "Launch Activity :"
 + pm.getLaunchIntentForPackage(packageInfo.packageName));
 }// the getLaunchIntentForPackage returns an intent that you can use
 // with startActivity()
 }

 public Context getmContext() {
 return mContext;
 }

 public void setmContext(Context mContext) {
 this.mContext = mContext;
 }

 public void StartApp(String appName) {
 Log.d("aaa", appName);
 Intent LaunchIntent;
 LaunchIntent = this.getmContext().getPackageManager()
 .getLaunchIntentForPackage(appName);
 this.getmContext().startActivity(LaunchIntent);

 }

 }*/
